<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>
<style>
  #div1 {
    width: 400px;
    height: 300px;
    background: #CCC;
    display: none;
  }
</style>
<script>
  window.onload = function () {
    let btn = document.getElementById("btn1")
    let div1 = document.getElementById("div1")
    btn.onclick = function (event) {
      div1.style.display = "block"
      event.cancelBubble = true
    }

    document.onclick = function () {
      div1.style.display = "none"
    }


  }
</script>

<body>
  <input id="btn1" type="button" value="显示" />
  <div id="div1"></div>
</body>

</html>